﻿namespace Pibby.Core.IO
{
	using System.IO;

	public class FolderContentVisitor : IFileVisitor
	{
		#region Constructors

		public FolderContentVisitor()
		{
			this.Files = new IFileCollection();
			this.Folders = new IFolderCollection();
		}

		#endregion

		#region IFileVisitor

		public bool Visit(IFile file)
		{
			this.Files.Add(file);

			return true;
		}

		public void Entering(IFolder folder)
		{
			this.Folders.Add(folder);
		}

		public void Leaving(IFolder folder)
		{
		}

		#endregion IFileVisitor

		public void ListContentsOf(IFolder startingPoint)
		{
			FileDiscoverer discoverer = new FileDiscoverer(this, 
														SearchOption.TopDirectoryOnly, 
														FileFilterConstants.AllFiles);

			discoverer.Process(startingPoint);
		}

		public IFileCollection Files
		{
			get;
			private set;
		}

		public IFolderCollection Folders
		{
			get;
			private set;
		}
	}
}
